//Sat Sep  3 08:36:10 CDT 2011
import java.util.HashSet;

/**
 * 
 */

/**
 * @author antonio081014
 * @date Sep 3, 2011
 * @time 8:25:01 AM
 */

public class FortunateNumbers {

	private HashSet<Integer> set;

	public int getFortunate(int[] a, int[] b, int[] c) {
		set = new HashSet<Integer>();
		for (int i : a) {
			for (int j : b) {
				for (int k : c) {
					int sum = i + j + k;
					if (check(sum)) {
						set.add(sum);
					}
				}
			}
		}
		return set.size();
	}

	public boolean check(int number) {
		while (number > 0) {
			int temp = number % 10;
			if (temp != 5 && temp != 8)
				return false;
			number /= 10;
		}
		return true;
	}
}
// Powered by [KawigiEdit] 2.0!
